<template>
  <div class="main-content">
    <div class="repo-summary">
      <h2>
        {{ repoName }} 镜像 版本数量: {{ pagination.total }}
      </h2>
      <div class="table-wrapper">
        <el-table :data="dataList" :row-class-name="tableRowClassName">
          <el-table-column fixed="left" prop="name" label="镜像">
            <template slot-scope="scope">
              <router-link
                :to="{ path: `/image/${scope.row.name}:${scope.row.tag}` }"
              >{{ scope.row.name }}:{{ scope.row.tag }}
                <!-- <el-button type="primary" plain size="small">{{ scope.row.name }}:{{ scope.row.tag }}</el-button> -->
              </router-link>
              </template
            >
          </el-table-column>
          <!-- <el-table-column
            fixed="right"
            prop="tag"
            label="tag"
            width="180"
          >
          </el-table-column> -->
          <el-table-column
            fixed="right"
            prop="num_images"
            label="下载次数"
            width="180"
          >
            <template slot-scope="scope">
              <el-tag :key="scope.row.num_images" type="success">
                {{ scope.row.num_download }}
              </el-tag>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page="pagination.page"
        :page-size="pagination.size"
        layout="total, prev, pager, next, jumper"
        :total="pagination.total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  created() {
    const { name } = this.$route.params
    this.repoName = name
    this.getList(1)
  },
  data() {
    return {
      repoName: '',
      searchResults: [{ name: 'test', count: 10 }],
      dataList: [],
      pagination: {
        total: 6,
        page: 1,
        size: 2
      }
    }
  },
  methods: {
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
      this.getList(val)
    },
    async getList(page = 1) {
      const search = this.repoName
      const { data: response } = await this.$http.get('image/repos/tags/', {
        params: {
          page,
          search
        }
      })
      if (response.code) {
        return this.$message.error(response.message)
      }
      this.dataList = response.results
      this.pagination = response.pagination
      console.log(this.dataList)
    }
  }
}
</script>

<style scoped>
.repo-summary {
  text-align: center;
  margin: 20px 0;
}
.main-content {
  color: #333;
  text-align: center;
  min-height: 900px;
  margin-top: 60px;
  margin: 0 auto;
  width: 80%; /* Adjust the width as needed */
}
.table-wrapper {
  display: flex;
  justify-content: center;
}
.el-table {
  width: auto; /* Adjust the table width as needed */
}
.el-table-column {
  text-align: left; /* Left align the text in columns */
}
.image-grid {
  margin-top: 20px;
  margin-bottom: 20px;
}
.el-table .warning-row {
  background: oldlace;
}
.el-table .success-row {
  background: #f0f9eb;
}
a {
    color: #3b71ca
}
.router-link {
  font-size: 1.25rem
}
</style>
